if (typeof inChat === 'undefined') {
    var inChat = false;
} else if (inChat === true) {
    inChat = false;
}

function joinChat(chat_name) { //funktion för att joina en chat, skickar användarnamn och chat-namn till servern som skickar tillbaka addID (se addID längre ner)
    var chatExists = true;
    for (var x = 0; x < chatrooms.length; x += 1) {
        if (chatrooms[x].indexOf(chat_name) > -1) {
            chatExists = false;
        }
    }

    if (chatExists) {
        socket.emit('joinChat', {chatRoom: chat_name});
    } else {
        $('#chat_room-test').append('<span class="10" style="display: block"><div class="message-container"><div class="message-author"><a href="profile.html?name=SERVER" target="_blank">SERVER</a></div><div class="message-image" style="background-image:url(bilder/server1.png);"><div class="message-account"></div></div><div class="message-overlay">I watch you when you sleep.</div>You have already joined ' + chat_name + '</div></span>');
        $('#chat_room-test').scrollTop($('#chat_room-test').prop("scrollHeight"));
    }
}

$(document).on("click", "#feedbackButton", function () {
    $('#startsida-content').css('top', '5%');
    $('#startsida-content').load('feedback.html');
});

$(document).on('click', '.slideoutnav', function() {
    if (inChat) {
        var chatname = $(this).attr('id');
        joinChat(chatname);
    } else {
        tempName = $(this).attr('id');
        $('#startsida-content').css('top', '5%');
        $('#startsida-content').load('chat-room.html');
    }
});